//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package SaveServlet.student;

import com.lyq.bean.service.S_Service;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(
        name = "AddStudent_Servlet",
        urlPatterns = {"/AddStudent_Servlet"}
)
public class AddStudent_Servlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public AddStudent_Servlet() {
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String No = request.getParameter("No");
        String name = request.getParameter("username");
        String sex = request.getParameter("sex");
        String age = request.getParameter("age");
        String collage = request.getParameter("collage");//学院
        String department = request.getParameter("department");//专业
        String pwd = request.getParameter("password");
        String campus = request.getParameter("campus");
        double gpa = Double.parseDouble(request.getParameter("gpa"));
        int major_id = Integer.parseInt(request.getParameter("major_id"));
        int yaer_id = Integer.parseInt(request.getParameter("year_id"));
        Boolean bool = (new S_Service()).add_S(No, name, sex, age, collage, department, pwd,campus,gpa,major_id,yaer_id);
        if (bool) {
            request.getSession().setAttribute("message", "学生用户添加成功！");
        } else {
            request.getSession().setAttribute("message", "该用户名已存在，学生用户添加失败！");
        }

        request.getSession().setAttribute("url", "jsp/student/m/AddStudent.jsp");
        request.getRequestDispatcher("Message.jsp").forward(request, response);
    }
}
